﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace FlickrHarmony {
    public partial class WaitForm : Form {
        public event DoWorkEventHandler DoWork;
		public event RunWorkerCompletedEventHandler CompletedWork;
		public string Label { set { lblMessage.Text = value; } }

		public WaitForm() { InitializeComponent(); }

		/// <summary>
		/// Do whatever work the caller has assigned to the handler
		/// </summary>
        private void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) {
            if (this.DoWork != null) { this.DoWork(sender, e); }
        }

        private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) {
			if (this.CompletedWork != null) {
				// run custom event
				this.CompletedWork(sender, e);
			} else {
				// default completion event
				if (e.Cancelled) {
					base.DialogResult = DialogResult.Cancel;
				} else {
					if (e.Error != null) { throw e.Error; }
					base.DialogResult = DialogResult.OK;
				}
			}
        }

        private void WaitTimer_Tick(object sender, EventArgs e) {
            this.WaitTimer.Stop();
            this.BackgroundWorker.RunWorkerAsync();
        }
    }
}